/*
 * Copyright (C) 2008 ZXing authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.zxing.client.android;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Collection;


/**
 * The main settings activity.
 * 系统设置的页面
 *
 * @author dswitkin@google.com (Daniel Switkin)
 */
public final class PreferencesActivity extends PreferenceActivity
    implements OnSharedPreferenceChangeListener {

//  public static final String KEY_DECODE_1D = "preferences_decode_1D";
//  public static final String KEY_DECODE_QR = "preferences_decode_QR";
//  public static final String KEY_DECODE_DATA_MATRIX = "preferences_decode_Data_Matrix";
  public static final String KEY_CUSTOM_PRODUCT_SEARCH = "preferences_custom_product_search";

  public static final String KEY_REVERSE_IMAGE = "preferences_reverse_image";
  public static final String KEY_PLAY_BEEP = "preferences_play_beep";
  public static final String KEY_VIBRATE = "preferences_vibrate";
  public static final String KEY_COPY_TO_CLIPBOARD = "preferences_copy_to_clipboard";
  public static final String KEY_FRONT_LIGHT = "preferences_front_light";
  public static final String KEY_BULK_MODE = "preferences_bulk_mode";
  public static final String KEY_REMEMBER_DUPLICATES = "preferences_remember_duplicates";
  public static final String KEY_SUPPLEMENTAL = "preferences_supplemental";
  public static final String KEY_SEARCH_COUNTRY = "preferences_search_country";

  public static final String KEY_HELP_VERSION_SHOWN = "preferences_help_version_shown";

  /**设置在扫描记录中发现在库中的条码存在的情况下，是否添加**/
  public static final String KEY_REMEMBER_ADD ="preferences_remember_add";
  /**条形码是否截取**/
  public static final String KEY_BARCODE_CUT  = "preferences_barcode_cut";
  
/*  <!--1.3、是否启用条码库，默认为否。 -->
  <!-- 1.4、是否启用产品资料库，默认为否。 -->
  <!-- 1.5、陌生条码是否自动加入条码库，默认为否。 -->*/
  public static final String KEY_ISIN_DATABASE ="preferences_isin_database";
  public static final String KEY_ISACTIVATE_PRODUCT ="preferences_isActivate_Product";
  public static final String KEY_AUTO_DATABASE_UNFAMILIARBAR ="preferences_auto_nufamilt";
  
  
  
  /**启动条码截取规则**/
  private CheckBoxPreference barcodeRute ; 

  @Override
  protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.preferences);

    PreferenceScreen preferences = getPreferenceScreen();
    preferences.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
    barcodeRute =  (CheckBoxPreference) preferences.findPreference(KEY_BARCODE_CUT);
  }

  @Override
  public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
	  
  }
  
  @Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
		Preference preference) {
	 if(preference.getKey().equals(KEY_BARCODE_CUT)){ 
		 showBarCodeRuleSetting();
	 }
	 System.out.println(barcodeRute.isChecked());
	  
	return false;
}
  
  private EditText info  ;
  
  private void showBarCodeRuleSetting(){
	  LayoutInflater factory = LayoutInflater.from(this) ;
		View settingView = factory.inflate(R.layout.rule_setting, (ViewGroup)findViewById(R.id.send_email_dialog_ll)) ;
		info = (EditText)settingView.findViewById(R.id.send_email_dialog_et);
		Dialog dialog = new AlertDialog.Builder(this)
//			.setIcon(R.drawable.pic_m) 
			.setTitle("设置条码截取自定义规则")
			.setPositiveButton("确定", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					Toast.makeText(PreferencesActivity.this, info.getText(), Toast.LENGTH_SHORT).show();
					System.out.println("dajiahao");
				}
			})
			.setNegativeButton("退出", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					
				}
			}).setView(settingView).create();
		dialog.show() ;
  }

}
